package mr.ali.webvideo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import mr.ali.webvideo.mapper.PrizesUserMapper;
import mr.ali.webvideo.model.PrizesUser;
import mr.ali.webvideo.service.IPrizesUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Mr-ali
 * @since 2025-09-06
 */
@Service
public class PrizesUserServiceImpl extends ServiceImpl<PrizesUserMapper, PrizesUser> implements IPrizesUserService {

    @Resource
    private PrizesUserMapper prizesUserMapper;

    @Override
    public PageInfo<PrizesUser> getPrizesUserList(Integer pageNum, Integer pageSize, Integer userId) {
        QueryWrapper<PrizesUser> queryWrapper = new QueryWrapper<>();
        if (userId != null && userId != 0) {
            queryWrapper.eq("user_id", userId);
        }
        queryWrapper.orderByDesc("gmt_create");
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(prizesUserMapper.selectList(queryWrapper));
    }

    @Override
    public void insertPrizesUser(PrizesUser prizesUser) {
        prizesUserMapper.insert(prizesUser);
    }
}
